package hu.u_szeged.inf.ovrt.filelister.commands;

import static hu.u_szeged.inf.ovrt.filelister.core.beans.Colors.ERROR;
import static hu.u_szeged.inf.ovrt.filelister.core.beans.Colors.INFO;
import hu.u_szeged.inf.ovrt.filelister.core.beans.ApplicationState;
import hu.u_szeged.inf.ovrt.filelister.ui.UserInterface;

import java.util.Map;

/**
 * Delete filter module.
 */
public class DelFilter extends AbstractCommand {

    /**
     * Constructor, that sets user interface.
     * @param ui user interface.
     */
    public DelFilter(UserInterface ui) {
        super(ui);
    }

    @Override
    public void execute(ApplicationState state, Map<String, String> parameters) {
        String parameter = null;
        String parameterTemp = null;

        if (parameters.containsKey("default")) {

            parameter = parameters.get("default");
            parameterTemp = parameter;
            parameter = parameter.replace("\\", "/");
            parameter = parameter.replace(".", "\\.");
            parameter = parameter.replace("?", ".");
            parameter = parameter.replace("*", ".*");
            if (state.getFilters().contains(parameter)) {
                this.getUi().printLn("Filter deleted: " + parameterTemp, INFO);
                state.delFilter(parameter);
            } else {
                getUi().printLn("Filter \"" + parameterTemp + "\" not exists: ", ERROR);
            }
        }

        /*List<String> filters = state.getFilters();

        Iterator it=filters.iterator();

        while(it.hasNext()){
            System.out.println(it.next().toString());

            }*/

        // TODO Auto-generated method stub
    }
}
